package com.guet.niit.Login.controller.agent;

import com.guet.niit.util.exitLogin;
import com.sun.javafx.stage.StageHelper;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Alert;
import javafx.scene.control.Button;
import javafx.scene.control.ButtonType;
import javafx.scene.input.MouseEvent;
import javafx.stage.Stage;

import java.io.IOException;
import java.util.Optional;

public class AgentMenuFxController {
    @FXML
    Button exit;

    /**
     * 查看利润报表
     * @param mouseEvent
     */
    public void selectProfit(MouseEvent mouseEvent) {
        //引用fxml样式
        Parent load = null;
        try {
            load = FXMLLoader.load(getClass().getResource("/fxml/agent/profitRecord.fxml"));

        } catch (IOException e) {
            e.printStackTrace();
        }
        //获取当前窗口，并将Scene更换为用户菜单的Scene
        ObservableList<Stage> stageList = StageHelper.getStages();
        stageList.get(0).setScene(new Scene(load));

        //读取利润报表
        ProfitRecordFxController.profitRecordFxController.readProfit();
    }

    /**
     * 退出
     * @param mouseEvent
     */
    public void exit(MouseEvent mouseEvent) {
        Alert alert = new Alert(Alert.AlertType.CONFIRMATION);
        alert.setHeaderText(null);
        alert.setContentText("您确定要退出吗？");
        Optional<ButtonType> result = alert.showAndWait();
        if (result.get() == ButtonType.OK){
//            Platform.exit();
            exitLogin.backtrack(AgentMenuFxController.class);
        }else {
            alert.close();
        }
    }

}
